package es.onlysolutions.gs.comm.utils;

import es.onlysolutions.arq.core.mvc.exception.IExceptionConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindException;
import org.springframework.validation.ObjectError;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

public class ExceptionHandler implements IExceptionConfiguration
{

    private static final Log logger = LogFactory.getLog( ExceptionHandler.class );

    public List<ObjectError> handleException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object, BindException bindException, Exception exception)
    {
        List<ObjectError> result = new ArrayList<ObjectError>(1);

        ObjectError error = new ObjectError("aplication", new String[]{"ieException"}, new String[]{exception.toString()},
                "Unexpected exception: {0} ");

        logger.error("General Error:", exception);

        result.add(error);

        return result;

    }
}
